// ==UserScript==
// @name         沙雕知乎视频
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.zhihu.com/
// @grant        GM_log

// ==/UserScript==
;(function () {
  'use strict'
  // Your code here...

  function debounce(fn, wait) {
    var timer = null
    return function () {
      if (timer !== null) {
        clearTimeout(timer)
      }
      timer = setTimeout(fn, wait)
    }
  }
  document.addEventListener('DOMNodeInserted', debounce(start, 200))

  function start() {
    ;['.VideoAnswerPlayer', '.ZVideoItem-player'].forEach(cls => {
      const nodes = document.querySelectorAll(cls)
      if (nodes.length > 0) {
        GM_log(`DOMNodeInserted---- excuted , 删掉视频 ${nodes.length} 个`)
        nodes.forEach(item => {
          let parent = item.parentNode
          while (parent && !parent.classList.contains('TopstoryItem-isRecommend')) {
            parent = parent.parentNode
          }
          if (parent) {
            parent.remove()
          }
        })
      }
    })
  }
  start()
})()
